package com.secondhand.service.Impl;

import com.secondhand.domain.user;
import com.secondhand.mapper.userMapper;
import com.secondhand.service.userService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Log4j2
@Service
public class userServiceImpl implements userService {

    @Autowired
    userMapper usermapper;

    @Override
    public user findByUserNameAndPassword(String username, String password) {
        return usermapper.findByUserNameAndPassword(username, password);
    }

    @Override
    public boolean saveUser(String username, String password) {
        if(usermapper.getUserByUserName(username)==null){
            usermapper.insertUser(username,password);
            return true;
        }else return false;
    }

    @Override
    public boolean deleteUser(String username) {
        return usermapper.deleteUser(username) > 0;
    }


    @Override
    public boolean getUserByUserName(String username) {
        return usermapper.getUserByUserName(username) != null;
    }

    @Override
    public int getUserIdByUserName(String username) {
        return usermapper.getUserIdByUserName(username);
    }

    @Override
    public int updateUser(user user) {
        return usermapper.updateById(user);
    }

}
